package git.soulbgm.security.session;

import git.soulbgm.common.constant.HttpStatus;
import git.soulbgm.utils.ResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.web.session.SessionInformationExpiredEvent;
import org.springframework.security.web.session.SessionInformationExpiredStrategy;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import java.io.IOException;

/**
 * 会话(session)信息过期策略类
 *
 * @author SoulBGM
 * @date 2020-08-03
 */
@Slf4j
@Component
public class SessionInformationExpiredStrategyImpl implements SessionInformationExpiredStrategy {

    @Override
    public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException, ServletException {
        int code = HttpStatus.UNAUTHORIZED;
        String msg = "会话过期,请重新登录";
        ResponseUtil.renderError(event.getResponse(), code, msg);
    }
}
